package com.service.impl;

import com.bean.entity.ScoreDistribution;
import com.bean.pojo.PageAssistant;
import com.bean.vo.ScoreDistributionVo;
import com.dao.ScoreDistributionMapper;
import com.service.ScoreDistributionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * User: 刘文雄
 * Date:2022/3/30 15:22
 * 成绩分布表基础业务逻辑
 */
@Service
public class ScoreDistributionServiceImpl implements ScoreDistributionService {

    @Autowired
    private ScoreDistributionMapper scoreDistributionMapper;
    public int save(ScoreDistribution t) throws Exception {
        int insert = scoreDistributionMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("新增信息失败");
    }
    @Override
    public int remove(ScoreDistribution t) throws Exception {
        int delete = scoreDistributionMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("删除信息失败");

    }
    @Override
    public int modify(ScoreDistribution t) throws Exception {
        int update = scoreDistributionMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改信息失败");
    }
    @Override
    public ScoreDistributionVo unique(ScoreDistribution t) throws Exception {

        List<ScoreDistributionVo> scoreDistributionVoList = scoreDistributionMapper.select(t);
        if (scoreDistributionVoList.size() !=1)
            throw new Exception("没有相关数据");

        return scoreDistributionVoList.get(0);
    }
    @Override
    public List<ScoreDistributionVo> query(ScoreDistribution t) {
        List<ScoreDistributionVo> distributionVoList = scoreDistributionMapper.select(t);
        return distributionVoList;
    }
    @Override
    public PageAssistant<ScoreDistributionVo> queryByPage(Map<String, Object> map, PageAssistant<ScoreDistributionVo> pa) {

        //设置并查询总记录数
        pa.setCount(scoreDistributionMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(scoreDistributionMapper.selectByPage(map));
        return pa;
    }
}
